We are migrating the bug tracker to github Issues. This is now the preferred way to report NASM bugs.

Self-registration is disabled due to spam issue (mail gorcunov@gmail.com or hpa@zytor.com to create an account)

Bug 3392916 - OMF: Group not used by default for symbol in an old MASM object file
Summary: OMF: Group not used by default for symbol in an old MASM object file
Status: OPEN
Alias: None
Product: NASM
Classification: Unclassified
Component: Assembler (show other bugs)
Version: 3.00.xx
Hardware: All All
: Medium normal
Assignee: nobody
URL:
Depends on:
Blocks:
 
Reported: 2024-07-20 12:34 PDT by E. C. Masloch
Modified: 2024-09-17 12:36 PDT (History)
5 users (show)

Obtained from: Built from git using configure
Generated by: Human
Bug category: Incorrect main output, Invalid main output, Unexpected or confusing behavior
Observed for: Development code
Regression: ---
Regression since:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description E. C. Masloch 2024-07-20 12:34:59 PDT
Test repo is at https://hg.pushbx.org/ecm/testwrt (includes sources, script file to build, and MASM assembler executable (closed source) from the 2018 free software release of MS-DOS v2)

Linker used is in https://pushbx.org/ecm/download/warplink.zip (rename wl.exe to warplink.exe and place in the DOS path)

It appears that for data in an object file created by MASM v1.10 referenced from NASM's object file, where both assembly language source files define a group, the symbol is not by default referenced with the group as expected. Appending ":wrt dg" to the extern directive fixes this, but from NASM documentation I assumed that the WRT would not be needed.


=== test.asm:
group dg code const data

section code
section const
section data align=2
%ifdef WRT
	extern usepacket:wrt dg
%else
	extern usepacket
%endif

section code
	global perror
perror:
	mov ax, usepacket
	times 256 nop

section data
===

=== debdata.asm
page 255,132

; Copyright (C) 1983 Microsoft Corp.
; Modifications copyright 2018 John Elliott
;           and copyright 2022 S. V. Nickolas.
;
; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the Software), to deal
; in the Software without restriction, including without limitation the rights
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the Software is
; furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in
; all copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
; IN THE SOFTWARE.
;
; MS-DOS is a Registered Trademark of Microsoft Corp.

code      segment   public word 'code'
code      ends

const     segment   public word
const     ends

data      segment   public word
data      ends

dg        group     code,const,data

data      segment   public word


	public usepacket

usepacket	db ?

data    ends
        end
===

Run output:

test$ NASM=~/proj/nasm/nasm ./mak.sh && mv test.exe testno.exe && NASM=~/proj/nasm/nasm ./mak.sh -DWRT && mv test.exe testyes.exe && bdiff testno.exe testyes.exe
NASM version 2.17rc0 compiled on Jul 20 2024
About to Execute : masm debdata debdata debdata;
The Microsoft MACRO Assembler
Version 1.10, Copyright (C) Microsoft Inc. 1981,82


Warning Severe
Errors  Errors
0       0
About to Execute : warplink /mx /as:1 test+debdata,test,test;

WarpLink 2.61 (05/11/93 Alpha) Copyright 1989-93 Michael Devore.
All rights reserved.

Warning in TEST.EXE
  Problem:  No stack segment was found for the EXE file.
  Solution: This is possibly an error in your program.
            An EXE file, unlike a COM file, must internally setup
            its own stack if it has no stack segment.  To create a
            COM file, use the /c option of WarpLink.


Total number of warnings: 1

EXE load image size: 001K
NASM version 2.17rc0 compiled on Jul 20 2024
About to Execute : masm debdata debdata debdata;
The Microsoft MACRO Assembler
Version 1.10, Copyright (C) Microsoft Inc. 1981,82


Warning Severe
Errors  Errors
0       0
About to Execute : warplink /mx /as:1 test+debdata,test,test;

WarpLink 2.61 (05/11/93 Alpha) Copyright 1989-93 Michael Devore.
All rights reserved.

Warning in TEST.EXE
  Problem:  No stack segment was found for the EXE file.
  Solution: This is possibly an error in your program.
            An EXE file, unlike a COM file, must internally setup
            its own stack if it has no stack segment.  To create a
            COM file, use the /c option of WarpLink.


Total number of warnings: 1

EXE load image size: 001K
File: testno.exe
000202: 00      [ 01 ]
test$


File dumps:

test$ podhex testno.exe
000000 4D 5A 05 01 02 00 00 00-20 00 01 00 01 00 00 00  >MZ...... .......<
000010 00 00 00 00 00 00 00 00-1E 00 00 00 00 00 00 00  >................<
000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  >................<
*
000200 B8 04 00 90 90 90 90 90-90 90 90 90 90 90 90 90  >................<
000210 90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90  >................<
*
000300 90 90 90 00 00                                   >.....<
000305
test$ podhex testyes.exe
000000 4D 5A 05 01 02 00 00 00-20 00 01 00 01 00 00 00  >MZ...... .......<
000010 00 00 00 00 00 00 00 00-1E 00 00 00 00 00 00 00  >................<
000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  >................<
*
000200 B8 04 01 90 90 90 90 90-90 90 90 90 90 90 90 90  >................<
000210 90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90  >................<
*
000300 90 90 90 00 00                                   >.....<
000305
Comment 1 E. C. Masloch 2024-07-20 12:43:37 PDT
If I replace the MASM object file by a NASM object file the problem is avoided:


	segment code public align=2 class=code
	segment const public align=2
	segment data public align=2
	group dg code const data

	segment data
	global usepacket
usepacket	resb 1
Comment 2 E. C. Masloch 2024-07-20 12:48:26 PDT
convlist.pl is not crucial to this test but it can be obtained from https://hg.pushbx.org/ecm/tractest/file/aba03f97df32/convlist.pl
Comment 3 E. C. Masloch 2024-07-20 13:02:54 PDT
It appears the symbol is emitted differently into the object file by MASM vs NASM: using https://github.com/boeckmann/omfdump (note the PUBDEF16 record)

test$ ~/proj/omfdump/omfdump debdata.obj > deb.txt
test$ ~/proj/omfdump/omfdump testdata.obj > test.txt
test$ diff -u deb.txt test.txt
--- deb.txt     2024-07-20 21:58:43.320645781 +0200
+++ test.txt    2024-07-20 21:58:46.196707044 +0200
@@ -1,40 +1,47 @@
-80 THEADR        3 bytes, checksum 3B (valid)
-   0000: 01 41                                            :  .A
-96 LNAMES       21 bytes, checksum FF (valid)
+80 THEADR       14 bytes, checksum FD (valid)
+   0000: 0c 54 45 53 54 44 41 54-41 2e 41 53 4d           :  .TESTDATA.ASM
+88 COMENT       36 bytes, checksum 27 (valid)
+   [NP=0 NL=0 UD=00] 00 Translator
+   0002: 20 54 48 45 20 4e 45 54-57 49 44 45 20 41 53 53  :   THE NETWIDE ASS
+   0012: 45 4d 42 4c 45 52 20 32-2e 31 36 2e 30 32 52 43  :  EMBLER 2.16.02RC
+   0022: 32                                               :  2
+96 LNAMES       26 bytes, checksum DB (valid)
    [0001] ''
-   0000: 00 04 43 4f 44 45 05 43-4f 4e 53 54 04 44 41 54  :  .
+   0000: 00 04 43 4f 44 45 04 43-4f 44 45 05 43 4f 4e 53  :  .
    [0002] 'CODE'
-   0001: 04 43 4f 44 45 05 43 4f-4e 53 54 04 44 41 54 41  :  .CODE
-   [0003] 'CONST'
-   0006: 05 43 4f 4e 53 54 04 44-41 54 41 02 44 47        :  .CONST
-   [0004] 'DATA'
-   000c: 04 44 41 54 41 02 44 47-                         :  .DATA
-   [0005] 'DG'
-   0011: 02 44 47                                         :  .DG
-98 SEGDEF16      7 bytes, checksum 14 (valid)
+   0001: 04 43 4f 44 45 04 43 4f-44 45 05 43 4f 4e 53 54  :  .CODE
+   [0003] 'CODE'
+   0006: 04 43 4f 44 45 05 43 4f-4e 53 54 04 44 41 54 41  :  .CODE
+   [0004] 'CONST'
+   000b: 05 43 4f 4e 53 54 04 44-41 54 41 02 44 47        :  .CONST
+   [0005] 'DATA'
+   0011: 04 44 41 54 41 02 44 47-                         :  .DATA
+   [0006] 'DG'
+   0016: 02 44 47                                         :  .DG
+98 SEGDEF16      7 bytes, checksum 13 (valid)
      WORD (A2) PUBLIC (C2) USE16 size 0000
      name 'CODE', class 'CODE'
-   0000: 48 00 00 02 02 01                                :  H.....
-98 SEGDEF16      7 bytes, checksum 14 (valid)
+   0000: 48 00 00 02 03 01                                :  H.....
+98 SEGDEF16      7 bytes, checksum 13 (valid)
      WORD (A2) PUBLIC (C2) USE16 size 0000
      name 'CONST'
-   0000: 48 00 00 03 01 01                                :  H.....
-98 SEGDEF16      7 bytes, checksum 12 (valid)
+   0000: 48 00 00 04 01 01                                :  H.....
+98 SEGDEF16      7 bytes, checksum 11 (valid)
      WORD (A2) PUBLIC (C2) USE16 size 0001
      name 'DATA'
-   0000: 48 01 00 04 01 01                                :  H.....
-9a GRPDEF        8 bytes, checksum 56 (valid)
+   0000: 48 01 00 05 01 01                                :  H.....
+9a GRPDEF        8 bytes, checksum 55 (valid)
      name 'DG'
      segment 'CODE'
      segment 'CONST'
      segment 'DATA'
-   0000: 05 ff 01 ff 02 ff 03                             :  .......
-a0 LEDATA16      5 bytes, checksum 58 (valid)
-                segment 'DATA', offset 0000
-   0000: 00                                               :  .
-90 PUBDEF16     16 bytes, checksum AF (valid)
-     segment 'DATA'
+   0000: 06 ff 01 ff 02 ff 03                             :  .......
+90 PUBDEF16     16 bytes, checksum AE (valid)
+     segment 'DATA' group 'DG'
    [0001] public name 'USEPACKET' offset 0000
-   0000: 00 03 09 55 53 45 50 41-43 4b 45 54 00 00 00     :  ...USEPACKET...
+   0000: 01 03 09 55 53 45 50 41-43 4b 45 54 00 00 00     :  ...USEPACKET...
+88 COMENT        4 bytes, checksum 91 (valid)
+   [NP=0 NL=1 UD=00] A2 Link pass separator
+   0002: 01                                               :  .
 8a MODEND16      2 bytes, checksum 74 (valid)
    0000: 00                                               :  .
test$
Comment 4 E. C. Masloch 2024-07-21 13:09:19 PDT
Update: I finished my port of MSDebug to NASM, which I managed by porting the data files debdata.nas and debconst.nas first so that the references do not need a wrt, as desired.

History is in the repo, eg https://hg.pushbx.org/ecm/msdebug/rev/26d5ab9640ec
Comment 5 E. C. Masloch 2024-07-28 08:09:38 PDT
Seems to affect object files built with MASM v5.10 as well, closed source executable included in the 2024 free software release of MS-DOS v4: https://hg.pushbx.org/ecm/msdos4/file/756d583bcddb/src/TOOLS/MASM.EXE
Comment 6 E. C. Masloch 2024-08-01 05:09:59 PDT
Running the same test with JWasm v2.18 does not reproduce the error. The PUBDEF16 record lists the group in that case.
Comment 7 E. C. Masloch 2024-09-17 12:36:35 PDT
Updates:

I was inspired this week, after modifying the fixupp tool recreation for Enhanced DR-DOS before: https://github.com/SvarDOS/edrdos/issues/61

I adapted the same tool to also add the group reference to PUBDEF records, which allows NASM-generated object files to reference the symbols of these records in the way expected from the NASM manual. More information in https://github.com/SvarDOS/edrdos/issues/113

This is the current revision: https://hg.pushbx.org/ecm/fixupp/file/d6a1e7757c5c/ltools/fixupp.c

@boeckmann added in the #113 thread that TASM also works as expected, similar to NASM and JWasm.

=== Quoting:

As another data point to your finding mentioned in the NASM bugzilla: Borland TASM also adds the group to publics with the segment being member of a group.

	ideal
	group 	dgroup data
	segment	data
	public	exported
exported:
	mov 	ax,1
	ends
	end

results in:

...
98 SEGDEF16      7 bytes, checksum FA (valid)
     PARA (A3) PRIVATE (C0) USE16 size 0003
     name 'DATA'
   0000: 60 03 00 02 01 01                                :  `.....
...
9a GRPDEF        4 bytes, checksum 5F (valid)
     name 'DGROUP'
     segment 'DATA'
   0000: 03 ff 01                                         :  ...
90 PUBDEF16     15 bytes, checksum EC (valid)
     segment 'DATA' group 'DGROUP'
   [0001] public name 'EXPORTED' offset 0000
   0000: 01 01 08 45 58 50 4f 52-54 45 44 00 00 00        :  ...EXPORTED...

=== End quoting